<?php
if(isset($_POST['ok'])){
	$val=new Helper_Validation;
	$val->check_empty($_POST['name'],ERROR_EMPTY_PRODUCT_NAME);
	if($val->valid() == FALSE){
		$data['error']=$val->err;
	}else{
		/* move_uploaded_file($_FILES['image1']['tmp_name'],"image/".$_FILES['image1']['name']);
		$image1="image/".$_FILES['image1']['name'];
		move_uploaded_file($_FILES['image2']['tmp_name'],"image/".$_FILES['image2']['name']);
		$image2="image/".$_FILES['image2']['name']; */
		
		uploadImage("image1","image/","image/thumbs/");
		$image1 = "image/".$_FILES['image1']['name'];
		$image1_thumb = "image/thumbs/".$_FILES['image1']['name']; 
		$date = date("Y-m-d");
		$data=array(
			"`name`" => $_POST['name'],
			"`desc`" => $_POST['desc'],
			"`thumb`"=> $image1_thumb,
			"`thumbnail`"=>$image1_thumb,
			"`image`"=>$image1,
			"`image1`"=>'',
			"`image2`"=>'',
			"`image3`"=>'',
			"`image4`"=>'',
			"`image1_thumb`"=>'',
			"`image2_thumb`"=>'',
			"`image3_thumb`"=>'',
			"`image4_thumb`"=>'',
			"`price`"=>$_POST['price'],
			"`price_origin`"=>'',
			"`quantity`"=>$_POST['quantity'],	
			"`origin` "=> $_POST['origin'],
			"`warranty`"=> $_POST['warranty'],
			"`status` "=> $_POST['status'],
			"`modified_date`"=> $date,
			"`detail`"=> $_POST['detail'],
			"`product_relate`"=> '',
			"`created_date`"=>$date,
			"`category_id`"=> $_POST['category'],
			"`price_add`"=>'',
			
		);
		$mproduct= new Model_Products;

		$mproduct->insert_product($data);
		redirect(BASE_URL."/index.php?module=product&act=list");
	
	}	
}
$mcategory= new Model_Categories;
$data['cate']=$mcategory->listall();
loadview("product/add_view",$data);
